<template>
  <div
    class="all-pass"
    v-loading="loading"
    element-loading-text="正在加载数据..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="left-box" v-if="!loading">
      <div class="playground-container">
        <div class="playground-top">
          <div class="little-block"></div>
          <div class="rate-block">{{ playgroundTopRate[0] + "%" }}</div>
          <div class="little-block"></div>
          <div class="rate-block">{{ playgroundTopRate[1] + "%" }}</div>
          <div class="little-block"></div>
          <div class="rate-block">{{ playgroundTopRate[2] + "%" }}</div>
          <div class="little-block"></div>
        </div>
        <NineCellPlayGround :zoneData="allPass.PassZone"></NineCellPlayGround>
        <div class="playground-right">
          <div class="little-block"></div>
          <div class="rate">{{ playgroundRightRate[0] + "%" }}</div>
          <div class="little-block"></div>
          <div class="rate">{{ playgroundRightRate[1] + "%" }}</div>
          <div class="little-block"></div>
          <div class="rate">{{ playgroundRightRate[2] + "%" }}</div>
          <div class="little-block"></div>
        </div>
        <div class="legend">
          <img
            class="attack-arrow"
            src="../../assets/image/playerGround/rightArrow.png"
            alt=""
          />
          <span class="legend-text">传球数/传球成功率</span>
        </div>
      </div>
    </div>
    <div class="right-box" v-if="!loading">
      <div class="ant-v">
        <div class="two-graph">
          <div class="one-graph">
            <div class="one-graph-title">总传球数/成功率</div>
            <AllScatter
              :all-pass="allPass.playerPass"
              :player-name="allPass.playerName"
            />
          </div>
          <div class="one-graph">
            <div class="one-graph-title">传球成功/90</div>
            <RoseTotal :rose-total="allPass.RoseTotal" />
          </div>
        </div>
        <div class="graph-legend">
          {{ allPass.playerName }}在中超传球数据与其他球员的对比
        </div>
      </div>
      <AllPassTableData :table="allPass.Table"></AllPassTableData>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import PassTotal from "../ant_v/allPass/PassTotal";
import PassSuccessful from "../ant_v/allPass/PassSuccessful";
import AllPassTableData from "../tableData/AllPassTableData";
import PlayGround from "../playground/PlayGround";
import NineCellPlayGround from "../playground/NineCellPlayGround";
import RosePass from "../ant_v/allPass/RosePass";
import AllScatter from "../ant_v/allPass/AllScatter";
import RoseTotal from "../ant_v/allPass/RoseTotal";
export default {
  name: "AllPass",
  props: {
    playerId: {
      type: Number,
    },
  },
  data() {
    return {
      allPass: "",
      loading: true,
    };
  },
  components: {
    PassTotal,
    PassSuccessful,
    AllPassTableData,
    PlayGround,
    NineCellPlayGround,
    RosePass,
    AllScatter,
    RoseTotal,
  },
  computed: {
    //计算纵向3个方向的传球成功率累加
    playgroundTopRate() {
      return [
        Math.round(
          (this.allPass["PassZone"][0]["passRatio"] +
            this.allPass["PassZone"][3]["passRatio"] +
            this.allPass["PassZone"][6]["passRatio"]) *
            100
        ) / 100,
        Math.round(
          (this.allPass["PassZone"][1]["passRatio"] +
            this.allPass["PassZone"][4]["passRatio"] +
            this.allPass["PassZone"][7]["passRatio"]) *
            100
        ) / 100,
        Math.round(
          (this.allPass["PassZone"][2]["passRatio"] +
            this.allPass["PassZone"][5]["passRatio"] +
            this.allPass["PassZone"][8]["passRatio"]) *
            100
        ) / 100,
      ];
    },
    //计算横向3个方向的传球成功率累加
    playgroundRightRate() {
      if (this.allPass["PassZone"] !== undefined) {
        return [
          Math.round(
            (this.allPass["PassZone"][0]["passRatio"] +
              this.allPass["PassZone"][1]["passRatio"] +
              this.allPass["PassZone"][2]["passRatio"]) *
              100
          ) / 100,
          Math.round(
            (this.allPass["PassZone"][3]["passRatio"] +
              this.allPass["PassZone"][4]["passRatio"] +
              this.allPass["PassZone"][5]["passRatio"]) *
              100
          ) / 100,
          Math.round(
            (this.allPass["PassZone"][6]["passRatio"] +
              this.allPass["PassZone"][6]["passRatio"] +
              this.allPass["PassZone"][8]["passRatio"]) *
              100
          ) / 100,
        ];
      }
    },
  },
  watch: {
    $route: {
      handler(to, from) {
        console.log("from:", from);
        console.log("to:", to);
        const { playerId } = to.params;
        // console.log("toId:", playerId);
        if (playerId) {
          this.getAllPass(playerId);
        }
      },
      immediate: true,
    },
  },
  async created() {
    // const playerId = this.$store.state.currPlayerId;
    // this.getAllPass(this.playerId);
    // this.getAllPass(playerId);
  },
  methods: {
    async getAllPass(playerId) {
      console.log(`当前页面球员id:${playerId}`);
      //发送请求获取allPass数据
      const { data } = await axios.get(
        `http://8.141.159.127:3000/api/v1/players/actions/pass/${playerId}`
      );
      //赋值
      this.allPass = data;
      //关闭'数据加载'
      this.loading = false;
    },
  },
};
</script>

<style scoped lang="scss">
.all-pass {
  display: flex;
  /*width: 100%;*/
  height: 100%;
  justify-content: space-between;
}
.left-box {
  height: 456px;
  margin-left: 90px;
}
.right-box {
  width: 560px;
  height: 413px;
  margin-top: 18px;
  margin-right: 70px;
  /*background-color: yellow;*/
}
.playground-container {
  position: relative;
  width: 620px;
  height: 456px;
  /*background-color: red;*/
  margin-top: 18px;
  .playground-top {
    display: flex;
    justify-content: space-between;
    width: 591px;
    /*<!--margin-top: -28px;-->*/
    color: #bd1e1e;
    line-height: 18px;
    font-size: 18px;
    height: 17px;
    /*margin-left: 20px;*/
    text-align: left;
    /*background-color: #656F73;*/
    .little-block {
      width: 3px;
      background-color: #bbbbbb;
      /*background-color: red;*/
    }
    .rate-block {
      width: 80px;
      text-align: center;
      /*background-color: #B500FE;*/
    }
  }
  .playground-right {
    /*display: inline-block;*/
    position: absolute;
    top: 30px;
    left: 603px;
    color: #bd1e1e;
    display: flex;
    /*flex-direction: column;*/
    justify-content: space-between;
    /*align-items: center;*/
    /*<!--margin-left: 9px;-->*/
    /*<!--margin-right: -28px;-->*/
    /*<!--margin-bottom: 17px;-->*/
    width: 17px;
    height: 383px;
    writing-mode: vertical-lr;
    font-size: 18px;
    /*background-color: red;*/
    .little-block {
      height: 3px;
      background-color: #bbbbbb;
      font-size: 25px;
    }
    .rate {
      /*background-color: red;*/
      line-height: 16px;
    }
  }
  .legend {
    display: flex;
    justify-content: space-between;
    /*align-items: center;*/
    /*background-color: yellow;*/
    font-size: 14px;
    width: 591px;
    height: 40px;
    /*margin-top: 22px;*/
    .attack-arrow {
      width: 150px;
      /*height: 40px;*/
    }
    .legend-text {
      line-height: 40px;
    }
  }
}
.ant-v {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /*background-color: red;*/
  line-height: 10px;
  width: 100%;
  height: 223px;
  .two-graph {
    display: flex;
    justify-content: space-between;
    .one-graph {
      width: 230px;
      height: 200px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .one-graph-title {
        height: 20px;
        line-height: 20px;
      }
    }
  }
  .graph-legend {
    height: 25px;
    color: #656f73;
    font-size: 14px;
    line-height: 25px;
  }
}
</style>
